Index: Modules/binascii.c =================================================================== --- Modules/binascii.c (revision 74244) +++ Modules/binascii.c (working copy) @@ -394,9 +394,13 @@ } } + /* Fail on non-base64-encoded character. */ this_ch = table_a2b_base64[*ascii_data]; - if ( this_ch == (unsigned char) -1 ) - continue; + if ( this_ch == (unsigned char) -1 ) { + PyErr_SetString(PyExc_TypeError, "Non-base64 digit found"); + Py_DECREF(rv); + return NULL; + } /* ** Shift it in on the low end, and see if there's Index: Lib/test/test_base64.py =================================================================== --- Lib/test/test_base64.py (revision 74244) +++ Lib/test/test_base64.py (working copy) @@ -120,7 +120,18 @@ eq(base64.urlsafe_b64decode('01a-b_cd'), '\xd3V\xbeo\xf7\x1d') def test_b64decode_error(self): - self.assertRaises(TypeError, base64.b64decode, 'abc') + ar = self.assertRaises + ar(TypeError, base64.b64decode, 'abc') + # Test some invalid characters; addresses [1466065]. + ar(TypeError, base64.b64decode, '%3d3LnB5dGhvbi5vcmc=') + ar(TypeError, base64.b64decode, '$3d3LnB5dGhvbi5vcmc=') + ar(TypeError, base64.b64decode, '[3d3LnB5dGhvbi5vcmc=') + ar(TypeError, base64.b64decode, ']3d3LnB5dGhvbi5vcmc=') + ar(TypeError, base64.b64decode, '{3d3LnB5dGhvbi5vcmc=') + ar(TypeError, base64.b64decode, '}3d3LnB5dGhvbi5vcmc=') + ar(TypeError, base64.b64decode, '@3d3LnB5dGhvbi5vcmc=') + ar(TypeError, base64.b64decode, '!3d3LnB5dGhvbi5vcmc=') + ar(TypeError, base64.b64decode, '#3d3LnB5dGhvbi5vcmc=') def test_b32encode(self): eq = self.assertEqual